//
//  UIAlertController+QTAdd.h
//  Pods
//
//  Created by 张俊博 on 16/9/7.
//
//

#import <UIKit/UIKit.h>

/**
 *  [UIAlertController showAlertInViewController:self
 *                                     withTitle:@"Test Alert"
 *                                       message:@"Test Message"
 *                             cancelButtonTitle:@"Cancel"
 *                        destructiveButtonTitle:@"Delete"
 *                             otherButtonTitles:@[@"First Other", @"Second Other"]
 *                                      tapBlock:^(UIAlertController *controller, UIAlertAction *action, NSInteger buttonIndex){
 *
 *                                           if (buttonIndex == controller.cancelButtonIndex) {
 *                                              NSLog(@"Cancel Tapped");
 *                                           } else if (buttonIndex == controller.destructiveButtonIndex) {
 *                                              NSLog(@"Delete Tapped");
 *                                           } else if (buttonIndex >= controller.firstOtherButtonIndex) {
 *                                              NSLog(@"Other Button Index %ld", (long)buttonIndex - controller.firstOtherButtonIndex);
 *                                           }
 *                                      }];
 */

NS_ASSUME_NONNULL_BEGIN

#if TARGET_OS_IOS
typedef void (^UIAlertControllerPopoverPresentationControllerBlock) (UIPopoverPresentationController * __nonnull popover);
#endif
typedef void (^UIAlertControllerCompletionBlock) (UIAlertController * __nonnull controller, UIAlertAction * __nonnull action, NSInteger buttonIndex);

@interface UIAlertController (QTAdd)

+ (nullable instancetype)showInViewController:(nonnull UIViewController *)viewController
                           withTitle:(nullable NSString *)title
                             message:(nullable NSString *)message
                      preferredStyle:(UIAlertControllerStyle)preferredStyle
                   cancelButtonTitle:(nullable NSString *)cancelButtonTitle
              destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle
                   otherButtonTitles:(nullable NSArray *)otherButtonTitles
#if TARGET_OS_IOS
  popoverPresentationControllerBlock:(nullable void(^)(UIPopoverPresentationController * __nonnull popover))popoverPresentationControllerBlock
                          sourceRect:(CGRect)rect
#endif
                            tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;

+ (instancetype)showAlertInViewController:(nonnull UIViewController *)viewController
                                        withTitle:(nullable NSString *)title
                                          message:(nullable NSString *)message
                                cancelButtonTitle:(nullable NSString *)cancelButtonTitle
                           destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle
                                otherButtonTitles:(nullable NSArray *)otherButtonTitles
                                         tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;

+ (instancetype)showAlertWithTitle:(nullable NSString *)title
                                   message:(nullable NSString *)message
                         cancelButtonTitle:(nullable NSString *)cancelButtonTitle
                         otherButtonTitles:(nullable NSArray *)otherButtonTitles
                                  tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;


+ (instancetype)showActionSheetInViewController:(nonnull UIViewController *)viewController
                                              withTitle:(nullable NSString *)title
                                                message:(nullable NSString *)message
                                      cancelButtonTitle:(nullable NSString *)cancelButtonTitle
                                 destructiveButtonTitle:(nullable NSString *)destructiveButtonTitle
                                      otherButtonTitles:(nullable NSArray *)otherButtonTitles
#if TARGET_OS_IOS
                     popoverPresentationControllerBlock:(nullable UIAlertControllerPopoverPresentationControllerBlock)popoverPresentationControllerBlock
                                             sourceRect:(CGRect)rect
#endif
                                               tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;

+ (instancetype)showActionSheetWithTitle:(nullable NSString *)title
                                         message:(nullable NSString *)message
                               cancelButtonTitle:(nullable NSString *)cancelButtonTitle
                               otherButtonTitles:(nullable NSArray *)otherButtonTitles
#if TARGET_OS_IOS
                                      sourceRect:(CGRect)rect
#endif
                                        tapBlock:(nullable UIAlertControllerCompletionBlock)tapBlock;


@property (readonly, nonatomic) BOOL visible;
@property (readonly, nonatomic) NSInteger cancelButtonIndex;
@property (readonly, nonatomic) NSInteger firstOtherButtonIndex;
@property (readonly, nonatomic) NSInteger destructiveButtonIndex;



@end

NS_ASSUME_NONNULL_END
